<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>在Vue组件中获得Vuex状态</title>
    <!--引入Vue库-->
    <script src="./vue.js"></script>
    <script src="./vuex.js"></script>
  </head>
  <body>
    <div id="app">
      <app-components></app-components>
    </div>
    <script>
      const store = new Vuex.Store({
        state: {
          count: 1,
        },
      });
      // 创建一个counter组件
      const counter = {
        template: `<div>count组件---{{ count }}</div>`,
        computed: {
          count() {
            return store.state.count;
          },
        },
      };
      const vm = new Vue({
        el: "#app",
        // 把store对象提供给“store”选项，这可以把store的实例注入所有的子组件
        store: store,
        components: { "app-components": counter },
      });
    </script>
  </body>
</html>
